//
//  YJImmediatelygrabCell.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/21.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJImmediatelygrabCell.h"
#import "YJSalesListModel.h"


@implementation YJImmediatelygrabCell

- (void)awakeFromNib {
    CGFloat w=(self.contentView.frame.size.width-20)/3.0;
    CGFloat h=self.contentView.frame.size.height;
    CGFloat padding=5;
    for (int i=0; i<3; i++) {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"YJImmediatelygrabView" owner:self options:nil];
        _sView=nib.lastObject;
        _sView.frame=CGRectMake(i*(w+padding)+padding, 0, w, h);
        _sView.tag=101+i;
        [self.contentView addSubview:_sView];
    }
}

-(void)showDataWithArray:(NSMutableArray *)ary myBlock:(ImmediateBlock)myBlock{
    self.ary=ary;
    self.myBlock=myBlock;
    for (int i=0; i<ary.count; i++) {
        YJImmediatelygrabView *SView=(YJImmediatelygrabView *)[self.contentView viewWithTag:i+101];
        [SView showDataWithModel:ary[i]];
        [SView addTarget:self action:@selector(click:)];
    }
}

-(void)click:(YJImmediatelygrabView *)view{
    if (self.myBlock) {
        YJSalesListModel *model=self.ary[view.tag -101];
        self.myBlock(model.id);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
